package com.ruoyi.web.controller.dingdan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysDingdan;
import com.ruoyi.system.domain.SysMarket;
import com.ruoyi.system.service.ISysDingdanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/dingdan")
public class DingdanController extends BaseController {
    @Autowired
    private ISysDingdanService iSysDingdanService;
    /**
     * 获取订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:dingdan:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDingdan dingdan)
    {
        startPage();
        List<SysDingdan> list = iSysDingdanService.selectDingdanList(dingdan);
        return getDataTable(list);
    }
    /**
     * 获取退款订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:dingdan:listoutpay')")
    @GetMapping("/listoutpay")
    public TableDataInfo listoutpay(SysDingdan dingdan)
    {
        startPage();
        List<SysDingdan> list = iSysDingdanService.selectDingdanListTwo(dingdan);
        return getDataTable(list);
    }
    /**
     * 导出订单列表
     */
    @Log(title = "订单列表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:dingdan:export')")
    @GetMapping("/export")
    public AjaxResult export(SysDingdan dingdan)
    {
        List<SysDingdan> list = iSysDingdanService.selectDingdanList(dingdan);
        ExcelUtil<SysDingdan> util = new ExcelUtil<SysDingdan>(SysDingdan.class);
        return util.exportExcel(list, "订单列表");
    }
    /**
     * 导出订单列表
     */
    @Log(title = "退款订单列表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:dingdan:export')")
    @GetMapping("/exportoutpay")
    public AjaxResult exportoutpay(SysDingdan dingdan)
    {
        List<SysDingdan> list = iSysDingdanService.selectDingdanListTwo(dingdan);
        ExcelUtil<SysDingdan> util = new ExcelUtil<SysDingdan>(SysDingdan.class);
        return util.exportExcel(list, "退款订单列表");
    }
    /**
     * 根据订单编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dingdan:query')")
    @GetMapping(value = "/{dingdanId}")
    public AjaxResult getInfo(@PathVariable int dingdanId)
    {
        return AjaxResult.success(iSysDingdanService.selectDingdanById(dingdanId));
    }
    /* *
     * 修改订单支付状态*/
    @PreAuthorize("@ss.hasPermi('system:market:edit')")
    @Log(title = "app管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysDingdan dingdan)
    {
        /*channel.setUpdateBy(SecurityUtils.getUsername());*/
        return toAjax(iSysDingdanService.updateDingdan(dingdan));
    }
}
